home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
Mops 2.7
/
Mops source
/
Asm Source
/
AsmUtilities
< prev
next >
Wrap
Text File
|
1993-07-25
|
4KB
|
154 lines
\ Assembler Utility Routines Reese Warner 4/85
\ 09/10/85 RW Changed auxA/D: to A/D:
\ 09/16/85 RW Made >num copy out its number
\ 03/06/86 GDC fixed immediate mode (>num)
\ 03/07/86 GDC fixed PC modes (9 & 10) (compIdxMode)
\ 10-May-87 MRH added range checking, and error messages in English
0 -> dlevel
objPtr OPPTR class_is operand
: >NUM { addr len \ neg? -- n } \ converts text into numbers
addr c@ & $ =
if 1 ++> addr 1 --> len hex then
addr c@ & - = dup -> neg? if 1 ++> addr 1 --> len then
0 0 addr len >number 2drop drop decimal
neg? +- ;
: ASMERROR { errNum -- }
cr ." asmerror# " errNum . ." in Line number " linect . cr
tib tiblen type cr
pos spaces & ^ emit cr
errNum
CASE
200 OF ." Error in loading AsmCodes" ENDOF
202 OF ." Bad operation size/format" ENDOF
203 OF ." Bad operand" ENDOF
205 OF ." Bad immediate operand" ENDOF
206 OF ." Error in loading Operands" ENDOF
207 OF ." Operand modes do not match" ENDOF
208 OF ." Operand not an address register" ENDOF
210 OF ." Bad register mask" ENDOF
211 OF ." Error in first pass" ENDOF
216 OF ." Object or word not in dictionary" ENDOF
217 OF ." Reserved word not followed by [" ENDOF
219 OF ." Register direct operand needed" ENDOF
245 OF ." Wrong mode for this instruction" ENDOF
246 OF ." Short absolute addr out of range" ENDOF
247 OF ." Byte displacement out of range" ENDOF
248 OF ." Word displacement out of range" ENDOF
249 OF ." Immediate operand too large" ENDOF
250 OF ." Branch out of range" ENDOF
251 OF ." Undefined label" ENDOF
252 OF ." Bad instruction mnemonic" ENDOF
253 OF ." Label already defined" ENDOF
254 OF ." Operand must be a number only" ENDOF
255 OF ." Wrong operand type for this instruction"
ENDOF
ENDCASE
cr abort ; \ Added abort so the "real" error doesn't
\ scroll off the screen!
: INRANGE?
within? nip ;
: WORDCHK { n err# -- n }
n -32768
err# 249 = IF $ FFFF ELSE $ 7FFF THEN
inRange? NIF err# asmError THEN
n $ FFFF and ;
: BYTECHK { n err# -- n }
n -128 err# 249 = IF $ FF ELSE $ 7F THEN
inRange? not IF err# asmError THEN
n $ FF and ;
: doneon null ;
: CHECK { opPtr mask -- }
1
opPtr mode: operand val" mode is"
<<
mask val" mask is "
and
NIF
245 asmError \ mode and mask do not match
THEN ;
: COMPIDXMODE \ ( opPtr -- )
-> opPtr
getpcmode: opPtr dup 8 <
IF drop mode: opPtr THEN
SELECT{
AnRelMode IS{
value: opPtr 248 wordChk w, }END
IndexMode IS{
value: opPtr 247 byteChk
auxilSize: opPtr 1- 11 << or
auxReg: opPtr 12 << or
A/D: opPtr 15 << or
w, }END
ShortAbsMode IS{
value: opPtr 246 wordChk w, }END
LongAbsMode IS{
value: opPtr , }END
PCrelMode IS{
abs: opPtr here - 248 wordChk w, }END
PCindexMode IS{
value: opPtr 247 byteChk
auxilSize: opPtr 1- 11 << or
auxReg: opPtr 12 << or
A/D: opPtr 15 << or
w, }END
ImmedMode IS{
opFmt
SELECT{
Bfmt IS{ value: opPtr 249 byteChk w, }END
Wfmt IS{ value: opPtr 249 wordChk w, }END
Lfmt IS{ value: opPtr , }END
DEFAULT{
}SELECT
}END
DEFAULT{
}SELECT ;
: MODESIZE \ ( opPtr -- size ) Returns the number of extra
\ words required for the addressing mode of the
\ passed-in operand. The operation word itself
\ isn't counted.
-> opPtr
getpcmode: opPtr dup 8 <
IF drop mode: opPtr THEN
SELECT{
AnRelMode IS{ 1 }END
IndexMode IS{ 1 }END
ShortAbsMode IS{ 1 }END
LongAbsMode IS{ 2 }END
PCRelMode IS{ 1 }END
PCindexMode IS{ 1 }END
ImmedMode IS{
opFmt
SELECT{
Bfmt IS{ 1 }END
Wfmt IS{ 1 }END
Lfmt IS{ 2 }END
Sfmt IS{ 2 }END
Dfmt IS{ 4 }END
Xfmt IS{ 6 }END
Pfmt IS{ 6 }END
DEFAULT{ 1
}SELECT
}END
DEFAULT{ 0
}SELECT ;